

/*
	Base Business Objects.
	(C) Lehavi Solutions	

*/
	
#region using	
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
#endregion


namespace BO
{	
	
	[Serializable]
	public partial class User : BLL.EntityBase
	{
		#region Constructors
		/// Empty Constructor
		public User()
		{
			InitializeDateProperties();
		}
		
		// Initialize all the none nullable datetime vars to 1.1.1900 (to avoid SQL crash on insert)
		private void InitializeDateProperties()
		{
		}
		
		/// <summary>
		/// DataRow Constructor
		/// </summary>
		/// <param name="dr"></param>
		internal User(DataRow dr)
		{
			InitializeDateProperties();
			if (dr.Table.Columns.Contains("ID"))
			{
				ID = Convert.ToInt32(dr["ID"]);
			}

			if (dr.Table.Columns.Contains("GoogleID"))
			{
				if (dr["GoogleID"].GetType() != typeof(DBNull))
					GoogleID = Convert.ToString(dr["GoogleID"]);
				else
					GoogleID = null;
			}

			if (dr.Table.Columns.Contains("Token"))
			{
				if (dr["Token"].GetType() != typeof(DBNull))
					Token = Convert.ToString(dr["Token"]);
				else
					Token = null;
			}

			if (dr.Table.Columns.Contains("ClarizenSession"))
			{
				if (dr["ClarizenSession"].GetType() != typeof(DBNull))
					ClarizenSession = Convert.ToString(dr["ClarizenSession"]);
				else
					ClarizenSession = null;
			}

			if (dr.Table.Columns.Contains("UserName"))
			{
				if (dr["UserName"].GetType() != typeof(DBNull))
					UserName = Convert.ToString(dr["UserName"]);
				else
					UserName = null;
			}

			if (dr.Table.Columns.Contains("ClarizenUserID"))
			{
				if (dr["ClarizenUserID"].GetType() != typeof(DBNull))
					ClarizenUserID = Convert.ToString(dr["ClarizenUserID"]);
				else
					ClarizenUserID = null;
			}

			if (dr.Table.Columns.Contains("GoogleOauthToken"))
			{
				if (dr["GoogleOauthToken"].GetType() != typeof(DBNull))
					GoogleOauthToken = Convert.ToString(dr["GoogleOauthToken"]);
				else
					GoogleOauthToken = null;
			}

			if (dr.Table.Columns.Contains("GoogleOauthSecret"))
			{
				if (dr["GoogleOauthSecret"].GetType() != typeof(DBNull))
					GoogleOauthSecret = Convert.ToString(dr["GoogleOauthSecret"]);
				else
					GoogleOauthSecret = null;
			}

		}		
		
		/// <summary>
		/// Explicit Table DataRow Constructor
		/// </summary>
		/// <param name="dr"></param>
		/// <param name="columnPrefix"></param>
		public User(DataRow dr, string columnPrefix)
		{
			if (dr.Table.Columns.Contains(columnPrefix + "ID"))
			{
				ID = Convert.ToInt32(dr[columnPrefix + "ID"]);
			}

			if (dr.Table.Columns.Contains(columnPrefix + "GoogleID"))
			{
				if (dr[columnPrefix + "GoogleID"].GetType() != typeof(DBNull))
					GoogleID = Convert.ToString(dr[columnPrefix + "GoogleID"]);
				else
					GoogleID = null;
			}

			if (dr.Table.Columns.Contains(columnPrefix + "Token"))
			{
				if (dr[columnPrefix + "Token"].GetType() != typeof(DBNull))
					Token = Convert.ToString(dr[columnPrefix + "Token"]);
				else
					Token = null;
			}

			if (dr.Table.Columns.Contains(columnPrefix + "ClarizenSession"))
			{
				if (dr[columnPrefix + "ClarizenSession"].GetType() != typeof(DBNull))
					ClarizenSession = Convert.ToString(dr[columnPrefix + "ClarizenSession"]);
				else
					ClarizenSession = null;
			}

			if (dr.Table.Columns.Contains(columnPrefix + "UserName"))
			{
				if (dr[columnPrefix + "UserName"].GetType() != typeof(DBNull))
					UserName = Convert.ToString(dr[columnPrefix + "UserName"]);
				else
					UserName = null;
			}

			if (dr.Table.Columns.Contains(columnPrefix + "ClarizenUserID"))
			{
				if (dr[columnPrefix + "ClarizenUserID"].GetType() != typeof(DBNull))
					ClarizenUserID = Convert.ToString(dr[columnPrefix + "ClarizenUserID"]);
				else
					ClarizenUserID = null;
			}

			if (dr.Table.Columns.Contains(columnPrefix + "GoogleOauthToken"))
			{
				if (dr[columnPrefix + "GoogleOauthToken"].GetType() != typeof(DBNull))
					GoogleOauthToken = Convert.ToString(dr[columnPrefix + "GoogleOauthToken"]);
				else
					GoogleOauthToken = null;
			}

			if (dr.Table.Columns.Contains(columnPrefix + "GoogleOauthSecret"))
			{
				if (dr[columnPrefix + "GoogleOauthSecret"].GetType() != typeof(DBNull))
					GoogleOauthSecret = Convert.ToString(dr[columnPrefix + "GoogleOauthSecret"]);
				else
					GoogleOauthSecret = null;
			}

		}
		#endregion
		
		
		#region CRUD Methods
		
		public void GetByID(object id)
		{
			BO.User user = BLL.Users.GetByID(id);
			
            ID = user.ID;
            GoogleID = user.GoogleID;
            Token = user.Token;
            ClarizenSession = user.ClarizenSession;
            UserName = user.UserName;
            ClarizenUserID = user.ClarizenUserID;
            GoogleOauthToken = user.GoogleOauthToken;
            GoogleOauthSecret = user.GoogleOauthSecret;
		}
		public int Insert()
		{
			OnPreInsert();
			return BLL.Users.Insert(this);
		}
		
		public override void Update()
		{
			OnPreUpdate();
			BLL.Users.Update(this);
		}
		
		public override void Delete()
		{
			OnPreDelete();
			BLL.Users.Delete(ID);
		}
		
		public override void SafeDelete()
		{
			OnPreDelete();
			BLL.Users.SafeDelete(ID);
		}
		
		public override void SafeDeleteCascade()
		{
			OnPreDelete();
			BLL.Users.SafeDeleteCascade(ID);
		}

		#endregion

		#region Properties
		
        public int ID { get; set; }
        public string GoogleID { get; set; }
        public string Token { get; set; }
        public string ClarizenSession { get; set; }
        public string UserName { get; set; }
        public string ClarizenUserID { get; set; }
        public string GoogleOauthToken { get; set; }
        public string GoogleOauthSecret { get; set; }
		
		#endregion

     
    }
	
}



